package com.traceability.trace.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.traceability.common.annotation.Log;
import com.traceability.common.core.controller.BaseController;
import com.traceability.common.core.domain.AjaxResult;
import com.traceability.common.enums.BusinessType;
import com.traceability.trace.domain.FarmerProducer;
import com.traceability.trace.service.IFarmerProducerService;
import com.traceability.common.utils.poi.ExcelUtil;
import com.traceability.common.core.page.TableDataInfo;

/**
 * 农户Controller
 * 
 * @author xulin
 * @date 2025-01-09
 */
@RestController
@RequestMapping("/traceability-trace/producer")
public class FarmerProducerController extends BaseController
{
    @Autowired
    private IFarmerProducerService farmerProducerService;

    /**
     * 查询农户列表
     */
    @PreAuthorize("@ss.hasPermi('traceability-trace:producer:list')")
    @GetMapping("/list")
    public TableDataInfo list(FarmerProducer farmerProducer)
    {
        startPage();
        List<FarmerProducer> list = farmerProducerService.selectFarmerProducerList(farmerProducer);
        return getDataTable(list);
    }

    /**
     * 导出农户列表
     */
    @PreAuthorize("@ss.hasPermi('traceability-trace:producer:export')")
    @Log(title = "农户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FarmerProducer farmerProducer)
    {
        List<FarmerProducer> list = farmerProducerService.selectFarmerProducerList(farmerProducer);
        ExcelUtil<FarmerProducer> util = new ExcelUtil<FarmerProducer>(FarmerProducer.class);
        util.exportExcel(response, list, "农户数据");
    }

    /**
     * 获取农户详细信息
     */
    @PreAuthorize("@ss.hasPermi('traceability-trace:producer:query')")
    @GetMapping(value = "/{producerId}")
    public AjaxResult getInfo(@PathVariable("producerId") Long producerId)
    {
        return success(farmerProducerService.selectFarmerProducerByProducerId(producerId));
    }

    /**
     * 新增农户
     */
    @PreAuthorize("@ss.hasPermi('traceability-trace:producer:add')")
    @Log(title = "农户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FarmerProducer farmerProducer)
    {
        return toAjax(farmerProducerService.insertFarmerProducer(farmerProducer));
    }

    /**
     * 修改农户
     */
    @PreAuthorize("@ss.hasPermi('traceability-trace:producer:edit')")
    @Log(title = "农户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FarmerProducer farmerProducer)
    {
        return toAjax(farmerProducerService.updateFarmerProducer(farmerProducer));
    }

    /**
     * 删除农户
     */
    @PreAuthorize("@ss.hasPermi('traceability-trace:producer:remove')")
    @Log(title = "农户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{producerIds}")
    public AjaxResult remove(@PathVariable Long[] producerIds)
    {
        return toAjax(farmerProducerService.deleteFarmerProducerByProducerIds(producerIds));
    }
}
